package com.dingup.paike.bean.querybean;

import com.dingup.util.GDateUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import static com.dingup.paike.util.ConstUtil.*;

/**
 * Created by wancheng on 2018/11/30.
 */
public class TeacherAvailableTimeQuery {

    private Integer sysSubjectId;

    private String teacherId;

    private String deptId;

    private List<String> day;

    private String before;

    private String after;

    private List<TimeInterval> timeIntervals;

    public Integer getSysSubjectId() {
        return sysSubjectId;
    }

    public void setSysSubjectId(Integer sysSubjectId) {
        this.sysSubjectId = sysSubjectId;
    }

    public String getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(String teacherId) {
        this.teacherId = teacherId;
    }

    public List<String> getDay() {
        return day;
    }

    public void setDay(List<String> day) {
        this.day = day;
    }

    public String getBefore() {
        return before;
    }

    public void setBefore(String before) {
        this.before = before;
    }

    public String getAfter() {
        return after;
    }

    public void setAfter(String after) {
        this.after = after;
    }

    public List<TimeInterval> getTimeIntervals() {
        return timeIntervals;
    }

    public void setTimeIntervals(List<TimeInterval> timeIntervals) {
        this.timeIntervals = timeIntervals;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public List<TimeInterval> getTime() {
        if (CollectionUtils.isEmpty(this.day)) {
            return null;
        }
        if (StringUtils.isBlank(this.before)) {
            before = TIME_GO_TO_WORK;
        }
        if (StringUtils.isBlank(this.after)) {
            after = TIME_OFF_DUTY;
        }
        List<TimeInterval> timeIntervals = new ArrayList<>();
        this.day.forEach(
                d -> {
                    StringBuilder dayTimeBefore = new StringBuilder(d);
                    StringBuilder dayTimeAfter = new StringBuilder(d);
                    TimeInterval timeInterval = new TimeInterval();
                    try {
                        timeInterval.setBefore(GDateUtil.getDateFromStr(dayTimeBefore.append(STRING_BLANK).append(before).toString()));
                        timeInterval.setAfter(GDateUtil.getDateFromStr(dayTimeAfter.append(STRING_BLANK).append(after).toString()));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    timeIntervals.add(timeInterval);
                }
        );
        this.timeIntervals = timeIntervals;
        return timeIntervals;
    }
}
